import BackTop from "components/content/backTop/BackTop.vue";
// 上拉刷新
import Refresh from "components/common/refresh/Refresh.vue";
import { POP, NEW, SELL } from "./const";

// 工具js 防抖与过滤器
import { debounce } from "common/utils.js";

const REFRESH = 130

export const backTopMixin = {
    components: {
        BackTop,
        Refresh
    },
    data() {
        return {
            isShowBackTop: false,
            isShow: true
        }
    },
    methods: {
        // 点击回顶
        backClick() {
            this.$refs.scroll.scroll.scrollTo(0, 0, 500);
        },
        // 判断回顶显示
        listenShowBackTop(position) {
            this.isShowBackTop = -position.y > 1000;
        },
        // 下拉刷新
        topRefresh(position) {
            // console.log(position.y);
            this.isShow = position.y > -70

            if (position.y > REFRESH) {
                this.$router.go(0)
            }
        }
    }

}


export const tabControlMixin = {
    data: function () {
        return {
            currentType: POP
        }
    },
    methods: {
        tabClick(index) {
            switch (index) {
                case 0:
                    this.currentType = POP
                    break
                case 1:
                    this.currentType = NEW
                    break
                case 2:
                    this.currentType = SELL
                    break
            }
            this.$refs.tabControl1.currentIndex = index;
            this.$refs.tabControl2.currentIndex = index;
        }
    }
}

// 每有一张图片加载好的时候 就刷新一遍页面长度
export const itemListenermixin = {
    data() {
        return {
            itemImgListener: null,
        }
    },
    mounted() {
        const refresh = debounce(this.$refs.scroll.refresh, 200);

        this.itemImgListener = () => {
            refresh();
        };
        this.$bus.$on("itemImageLoad", this.itemImgListener);
        console.log('我是刷了');
    }
}